package mostFrequent;

public class Solution {
    public int mostFrequent(int[] nums, int key) {
        // nums[key] == key
        int[] marks = new int[1001];
        int target = 0;
        for (int i = 0; i < nums.length-1; i++) {
            if(nums[i]==key) {
                marks[nums[i]]++;
                if(marks[target] < marks[nums[i]]) {
                    target = nums[i];
                }
            }
        }
        return target;
    }
}
